package com.yanfan.energy.service.impl;

import java.util.Arrays;
import java.util.List;
import com.yanfan.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yanfan.energy.mapper.NjEnergyDeviceMapper;
import com.yanfan.energy.domain.NjEnergyDevice;
import com.yanfan.energy.service.INjEnergyDeviceService;

/**
 * 能耗采集器设备Service业务层处理
 *
 * @author genluo
 * @date 2024-10-29
 */
@Service
public class NjEnergyDeviceServiceImpl extends ServiceImpl<NjEnergyDeviceMapper, NjEnergyDevice> implements INjEnergyDeviceService {
    @Autowired
    private NjEnergyDeviceMapper njEnergyDeviceMapper;


    /**
     * 查询能耗采集器设备列表
     *
     * @param njEnergyDevice 能耗采集器设备
     * @return 能耗采集器设备
     */
    @Override
    public List<NjEnergyDevice> queryPageList(NjEnergyDevice njEnergyDevice) {
        LambdaQueryWrapper<NjEnergyDevice> lqw = buildQueryWrapper(njEnergyDevice);
        return njEnergyDeviceMapper.selectList(lqw);
        //连表查询可用该方法，在此方法SQL语句上进行扩展
        //return njEnergyDeviceMapper.queryPageList(njEnergyDevice);
    }

    /**
    * 分页查询条件
    * @return
    */
    private LambdaQueryWrapper<NjEnergyDevice> buildQueryWrapper(NjEnergyDevice bo) {
        LambdaQueryWrapper<NjEnergyDevice> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getSlaveIdCount() != null, NjEnergyDevice::getSlaveIdCount, bo.getSlaveIdCount());
        lqw.like(StringUtils.isNotBlank(bo.getDeviceName()), NjEnergyDevice::getDeviceName, bo.getDeviceName());
        lqw.eq(StringUtils.isNotBlank(bo.getIp()), NjEnergyDevice::getIp, bo.getIp());
        lqw.eq(StringUtils.isNotBlank(bo.getIdentifier()), NjEnergyDevice::getIdentifier, bo.getIdentifier());
        return lqw;
    }



}
